$(document).ready(function (){
	view_init();
	event_init();
});

function view_init()
{
	loadingStart();
	
	$("[data-type=dateAll]").each(function (){
		$(this).datetimepicker({
			  timeFormat: "HH:mm:ss",
	          dateFormat: "yy-mm-dd",
			  monthNames: [ "一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月" ]
		});
	});
	
	list_list(true);
	
	$("#main-content").show();
}

function event_init()
{
	// 查询按钮
	$("#query").click(function (){
		$("#list_tbody").html("");
		list_list(true);
	});
	
	// 详情按钮
	$("#list_tbody").delegate("[data-id=detail]" ,"click" ,function (){
		window.location.href = "/appuser/direction/detail.do?id="+$(this).parent().attr("data-id");
	});
	
	// 翻页事件
	index_initPageEvent("list_list()");
}

function list_list(isFirst)
{
	if (isFirst)
	{
		index_pageObj.init();
	}
	
	loadingStart();
	
	var obj = $("#query_panel").umDataBind("serialize" ,"");
	obj.currentPage = index_pageObj.currentPage;
	obj.pageSize = index_pageObj.pageSize;
	
	um_ajax_post(
			INDEX_WEBAPP + "/appuser/select.do",
			obj,
			function (data){
				$("#page_record_count").text(data.size);
				_render(data.appusers);
			},
			null);
	function _render(data)
	{
		var buffer = [];
		if (data && data.length >0)
		{
			for (var i=0;i<data.length;i++)
			{
				buffer.push('<tr>');
				buffer.push('<td>'+(((obj.currentPage-1)*obj.pageSize)+i+1)+'</td>');
				buffer.push('<td>'+data[i].userAccount+'</td>');
				buffer.push('<td>'+data[i].userName+'</td>');
				buffer.push('<td>'+data[i].registerDate+'</td>');
				buffer.push('<td style="text-align: center" data-id="'+data[i].userAccount+'"><a href="#" data-id=detail>详情</a></td>');
				buffer.push('<tr>');
			}
			$("#list_tbody").html(buffer.join(""));
		}
		else
		{
			index_pageObj.toEndPage();
		}

		index_pageObj.isEndMethod(data);

	}
}

function render_province(data)
{
	var buffer = [];
	for (var i=0;i<data.length;i++)
	{
		buffer.push('<option value="'+data[i]+'">'+data[i]+'</option>');
	}
	$("[data-id=userLocation]").append(buffer.join(""));
}